package com.juzipi.demo.tools;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {


    private Boolean flag;
    private Integer code;
    private String message;
    private Object data;


    /**
     * 成功无返回值
     * @param
     * @return
     */
    public static Result success(){

        return new Result(true,200,"SUCCESS",null);
    }


    /**
     * 成功带返回值
     * @param data
     * @return
     */
    public static Result success(Object data){
        return new Result(true,200,"SUCCESS",data);
    }



    /**
     * 成功消息带返回值
     * @param data
     * @return
     */
    public static Result success(String message,Object data){
        return new Result(true,200,message,data);
    }


    /**
     * 成功自定义返回信息
     * @param message
     * @return
     */
    public static Result success(String message){
        return new Result(true,200,message,null);
    }


    /**
     * 失败自定义状态码无返回值
     * @param code
     * @return
     */
    public static Result fail(Integer code){
        return new Result(false,code,"ERROR",null);
    }


    /**
     * 失败带返回值自定义状态码
     * @param code
     * @param data
     * @return
     */
    public static Result fail(Integer code,Object data){
        return new Result(false,code,"ERROR",data);
    }



    public static Result fail(Integer code,String message){
        return new Result(false,code,message,null);
    }

}
